package com.iiiss.ssh.impl.daos;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.iiiss.ssh.core.daos.ColumnDao;
import com.iiiss.ssh.core.entities.Column;

@Repository
public class ColumnDaoImpl extends BaseDaoImpl implements ColumnDao {

	public Column insert(String name) {
		Column column = super.createPersistedEntity(Column.BEAN_NAME, Column.class);
		column.setName(name);
		return column;
	}

	public Column insert(String name, Column parent) {
		Column column = this.insert(name);
		column.setParent(parent);
		parent.getChildren().add(column);
		return column;
	}

	public Column selectOne(Long id) {
		Column column = super.findEntity(Column.BEAN_NAME, Column.class, id);
		column.getChildren().isEmpty();
		return column;
	}

	public List<Column> selectAll() {
		List<Column> columns = super.findEntities(Column.BEAN_NAME, Column.class);
		for (Column column : columns)
			column.getChildren().isEmpty();
		return columns;
	}

	public void delete(Column column) {
		super.entityManager.remove(column);
	}

}
